package jgrit.gui;
import java.awt.FileDialog;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

import jgrit.gui.factory.UIFactory;
import jgrit.options.OptionCollection;

import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class FileOptionsPanel extends javax.swing.JPanel {
	private static final long serialVersionUID = -2922200185984232840L;
	
	private JTextField outputFileTextField;
	private JComboBox outputTypeComboBox;
	private JLabel jLabel5;
	private JButton jButton1;
	private JTextField externalTilesetTextField;
	private JPanel extTilesetPanel;
	private JTextField baseSymbolNameField;
	private JCheckBox riffOption;
	private JCheckBox appendOption;
	private JCheckBox headerOption;
	private JCheckBox pedanticOption;
	private JButton fileSelectButton;
	private JPanel outputFilePanel;
	private JComboBox arraySizeComboBox;

	/**
	* Auto-generated main method to display this 
	* JPanel inside a new JFrame.
	*/
	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.getContentPane().add(new FileOptionsPanel());
		frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
		frame.pack();
		frame.setVisible(true);
	}
	
	@Deprecated
	public FileOptionsPanel() {
		this(new OptionCollection());
	}
	
	public FileOptionsPanel(OptionCollection options) {
		super();
		initGUI(options);
	}
	
	private void initGUI(OptionCollection options) {
		try {
			FormLayout thisLayout = new FormLayout(
					"5dlu, max(p;5dlu), 5dlu, max(p;5dlu):grow, 5dlu, max(p;5dlu), 5dlu, max(p;5dlu):grow, 5dlu", 
					"5dlu, max(p;5dlu), 5dlu, max(p;5dlu), 5dlu, max(p;5dlu), max(p;5dlu), max(p;5dlu), max(p;5dlu), 5dlu, max(p;5dlu), 5dlu, max(p;5dlu), 5dlu");
			this.setLayout(thisLayout);
			{
				final JLabel jLabel1 = new JLabel();
				this.add(jLabel1, new CellConstraints("2, 2, 1, 1, default, default"));
				jLabel1.setText("Output file");
			}
			{
				final JLabel jLabel2 = new JLabel();
				this.add(jLabel2, new CellConstraints("2, 4, 1, 1, default, default"));
				jLabel2.setText("Output type");
			}
			{
//				ComboBoxModel outputTypeComboBoxModel = 
//					new DefaultComboBoxModel(
//							new String[] { "C (*.c)", "GAS (*.s)",
//								"Binary (*.bin)", "GBFS (*.gbfs)",
//								"RIFF (*.grf)" });
				outputTypeComboBox = new JComboBox();
				this.add(outputTypeComboBox, new CellConstraints("4, 4, 1, 1, default, default"));
//				outputTypeComboBox.setModel(outputTypeComboBoxModel);
				UIFactory.attachOption(options.fileFormat, outputTypeComboBox);
			}
			{
				final JLabel jLabel3 = new JLabel();
				this.add(jLabel3, new CellConstraints("6, 4, 1, 1, default, default"));
				jLabel3.setText("Array size");
			}
			{
				// This option is:
				//   Data-type (-U<n>). Arrays are in bytes, halfwords or words. Has no effect on binary or GBFS files.
				// so it needs to be disabled in those cases
//				ComboBoxModel arraySizeComboBoxModel = 
//					new DefaultComboBoxModel(
//							new String[] { "u8", "u16", "u32" });
				arraySizeComboBox = new JComboBox();
//				arraySizeComboBoxModel.setSelectedItem("u16");
				this.add(arraySizeComboBox, new CellConstraints("8, 4, 1, 1, default, default"));
//				arraySizeComboBox.setModel(arraySizeComboBoxModel);
				UIFactory.attachOption(options.arrayDataType, arraySizeComboBox);
			}
			{
//				outputFilePanel = new JPanel();
				outputFilePanel = UIFactory.createFileSelectComponent(options.destinationFile, FileDialog.SAVE);
//				FormLayout outputFilePanelLayout = new FormLayout(
//						"max(p;5dlu):grow, 2dlu, max(p;5dlu)", 
//						"max(p;5dlu)");
//				outputFilePanel.setLayout(outputFilePanelLayout);
				this.add(outputFilePanel, new CellConstraints("4, 2, 5, 1, default, default"));
//				{
//					outputFileTextField = new JTextField();
//					outputFilePanel.add(outputFileTextField, new CellConstraints("1, 1, 1, 1, default, default"));
//					GritGUIFactory.attachOption(options.destinationFolder, outputFileTextField);
//				}
//				{
//					fileSelectButton = new JButton();
//					outputFilePanel.add(fileSelectButton, new CellConstraints("3, 1, 1, 1, default, default"));
//					fileSelectButton.setText("...");
//				}
			}
			{
				headerOption = new JCheckBox();
				this.add(headerOption, new CellConstraints("2, 6, 7, 1, default, default"));
				headerOption.setText(options.includeHeader.getName());
				UIFactory.attachOption(options.includeHeader, headerOption);
			}
			{
				appendOption = new JCheckBox();
				this.add(appendOption, new CellConstraints("2, 7, 7, 1, default, default"));
				appendOption.setText(options.append.getName());
				UIFactory.attachOption(options.append, appendOption);
			}
			{
				pedanticOption = new JCheckBox();
				this.add(pedanticOption, new CellConstraints("2, 8, 7, 1, default, default"));
				pedanticOption.setText(options.pedantic.getName());
				UIFactory.attachOption(options.pedantic, pedanticOption);
			}
			{
				riffOption = new JCheckBox();
				this.add(riffOption, new CellConstraints("2, 9, 7, 1, default, default"));
				riffOption.setText(options.riffOption.getName());
				UIFactory.attachOption(options.riffOption, riffOption);
			}
			{
				final JLabel jLabel4 = new JLabel();
				this.add(jLabel4, new CellConstraints("2, 11, 1, 1, default, default"));
				jLabel4.setText("Base symbol name");
			}
			{
				baseSymbolNameField = new JTextField();
				this.add(baseSymbolNameField, new CellConstraints("4, 11, 5, 1, default, default"));
				UIFactory.attachOption(options.symbolBaseName, baseSymbolNameField);
			}
			{
				jLabel5 = new JLabel();
				this.add(jLabel5, new CellConstraints("2, 13, 1, 1, default, default"));
				jLabel5.setText("External tileset");
			}
			{
//				extTilesetPanel = new JPanel();
				extTilesetPanel = UIFactory.createFileSelectComponent(
						options.externalTileset, FileDialog.LOAD);
				this.add(extTilesetPanel, new CellConstraints(
						"4, 13, 5, 1, default, default"));
//				FormLayout jPanel1Layout = new FormLayout(
//						"max(p;5dlu):grow, 2dlu, max(p;5dlu)", 
//						"max(p;5dlu)");
//				extTilesetPanel.setLayout(jPanel1Layout);
//				{
//					externalTilesetTextField = new JTextField();
//					extTilesetPanel.add(externalTilesetTextField, new CellConstraints("1, 1, 1, 1, default, default"));
//					GritGUIFactory.attachOption(options.externalTileset, externalTilesetTextField);
//				}
//				{
//					jButton1 = new JButton();
//					extTilesetPanel.add(jButton1, new CellConstraints("3, 1, 1, 1, default, default"));
//					jButton1.setText("...");
//				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
